package com.ug1yk.dy_download_utils;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

public class MainActivity extends FlutterActivity {
    private static final String TAG = "MainActivity";
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);


    }


    //该方法用于获取intent所包含的文本信息，并显示到APP的Activity界面上
    private void handlerText(Intent intent) {
        String data = intent.getStringExtra(Intent.EXTRA_TEXT);
        Log.d(TAG, "handlerText() called with: data = [" + data + "]");
        ShareInstance.instance.getUrlLive().postValue(data);
    }

    @Override
    protected void onStart() {
        super.onStart();
        //获取intent
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
        //设置接收类型为文本
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                handlerText(intent);
            }
        }
    }

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);
        new BtChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), MainActivity.this);
    }
}
